package com.whynot.frame.manythread;
/**
 * 描    述:ThreadLocal
 * 创建时间: 2018/12/24
 */
public class MyThreadLocal {
	
	private static ThreadLocal<String> th = new ThreadLocal<String>();
	
	public void setValue(String v){
		th.set(v);
	}
	
	public void getValue(){
		System.out.println("当前线程"+Thread.currentThread().getName()+"的值："+this.th.get());
	}
	
	public static void main(String[] args) {
		final MyThreadLocal threadLocal = new MyThreadLocal();
		Thread t1 =new Thread(new Runnable() {
			
			public void run() {
				threadLocal.setValue("chenyao");
				threadLocal.getValue();
			}
		},"t1");
		
		Thread t2 =new Thread(new Runnable() {
			
			public void run() {
				threadLocal.getValue();
			}
		},"t2");
		t1.start();
		t2.start();
	}
}
